from flask import Blueprint, request, jsonify, g ,json
from flask_restful import Api, Resource, reqparse,marshal
from flask_sqlalchemy import Pagination
from models.models import *
from utils.jwt_tool import gen_toen,check_token
from utils.models_fields import *
common_bp = Blueprint("common",__name__)


api = Api(common_bp)


class Common(Resource):
    def get(self):
        parser = reqparse.RequestParser()
        parser.add_argument('id')
        args = parser.parse_args()
        id = args.get('id')
        common: Pagination = Appraise.query.filter_by(id=id).paginate(1,2,error_out=False)
        common_ser = marshal(common.items,common_fields)
        print(common.items)
        print(common_ser)
        common_dict = json.loads(json.dumps(common_ser))
        print(common_dict)
        stu = Stu.query.filter_by(id=Appraise.stu_id).first()
        for i in common_dict:
            data = {
                'id':i["id"],
                'uid':stu.id,
                'content':i["content"],
                'grade':stu.gender,
                'created_at':i["create_time"],
                'nickname':stu.phone
            }
            return jsonify(msg='获取成功',code=200,list=data,total=common.total)
api.add_resource(Common,'/common')